package rad.framework.mda.jpagen.actions;

import rad.framework.mda.generator.Console;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.uml2.uml.Class;
import org.eclipse.uml2.uml.PrimitiveType;
import org.eclipse.uml2.uml.Property;

/**
 * @author boudyacho
 * 
 */
public class AddOplockActionExtension extends BaseUtiltiyActionExtension {

	protected static final String VERSION = "javax.persistence.Version";

	public void fillContextMenu(IMenuManager aMenu) {
		getSubMenu(aMenu).add(new AddOplockAction());
	}

	protected void execute(Class clazz) {
		PrimitiveType type = getPrimitiveType(clazz, "Timestamp");
		Property property = clazz.createOwnedAttribute("oplock", type, 1, 1);
		applyStereotype(property, VERSION);
		addComment(property, "The optimistic lock property.");
		Console.getStream().println(
				"Added Oplock to  " + clazz.getQualifiedName());
	}

	private class AddOplockAction extends BaseUtilityAction {
		private static final String LABEL = "Add Oplock Property with Version Stereotypes";

		public AddOplockAction() {
			super(LABEL);
		}
	}
}
